﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataCoreTechnologies.SqlServer
{
   /// <summary>
   /// Contains information descripting a default value that is being applied to a column.
   /// </summary>
   public sealed class DefaultValue
   {
      #region Public
      //Properties
      /// <summary>
      /// A number that uniquely identifies this class instance.
      /// </summary>
      public Guid InstanceId { get; private set; }
      /// <summary>
      /// The column this default value is being applied against.
      /// </summary>
      public Column Column { get; private set; }
      /// <summary>
      /// The date this default value was created.
      /// </summary>
      public DateTime CreateDate { get; internal set; }
      /// <summary>
      /// The last time this default value was modified.
      /// </summary>
      public DateTime ModifyDate { get; internal set; }
      /// <summary>
      /// A title used by the database to identify this default value.
      /// </summary>
      public string Name { get; internal set; }
      /// <summary>
      /// The algorithm used to determine the default value.
      /// </summary>
      public string Formula { get; internal set; }
      /// <summary>
      /// A collection of name / value pairs used to describe this default value.
      /// </summary>
      public IEnumerable<ExtendedProperty> ExtendedProperties
      {
         get
         {
             for (int index = 0; index < _extendedProperties.Count; index++)
             {
                 yield return _extendedProperties[index];
             }
         }
      }
      #endregion
      #region Internal
      /// <summary>
      /// A number used to uniquely identify this default value within the database.
      /// </summary>
      internal int Id { get; set; }
      /// <summary>
      /// Creates an instance of a default value and associates it with the column indicated by the parameter.
      /// </summary>
      /// <param name="container">The parameter this default value is being applied against.</param>
      internal DefaultValue(Column container)
      {
         InstanceId = System.Guid.NewGuid();
         Column = container;
      }
      /// <summary>
      /// Associates a extended property to this default value.
      /// </summary>
      /// <param name="extendedProperty">The extended property that applied to this default value.</param>
      internal void AddExtendedProperty(ExtendedProperty extendedProperty) { _extendedProperties.Add(extendedProperty); }
      #endregion
      #region Private
      private List<ExtendedProperty> _extendedProperties = new List<ExtendedProperty>();
      #endregion
   }
}
